﻿	      <?php include("../common/conn.php");
             mysql_query('SET NAMES UTF8'); 

	  

class MyPrizeBean
{
	
	public $images;
	public $shopid;
	public $title;
	public $content;
	public $distance;
	public $evaluate;
	public $reply;
	public $like;
	public $phone;
	public $address;
	public $logs;
	public $regs;
	public $category;
	public $cityid;
	public $city;
	public $open;
	public $start_price;
	public $distribution_fee;
	public $song_da;
	public $leimu;
	public $alipay;
	public $alipay_name;
	public $weipay;
	public $weipay_name;
	public $licence;
	public $htservices;
	public $kgservices;	
	public $name;
	public $isHaitao;
	public $isKuaigou;
	public $qq;
	public $huodong_miaoshu;
	public $kgfanquan;
	public $htfanquan;
	public $kgservice;
	public $htservice;
	public $freight_ins;
	public $zileimu;
	
	function __construct($images,$shopid,$title,$content,$distance,$evaluate,$reply,$like,$phone,$address,$logs,$regs,$category,$cityid,$city,$open,$start_price,$distribution_fee,$song_da,$leimu,$alipay,$alipay_name,$weipay,$weipay_name,$licence,$htservices,$kgservices,$name,$isHaitao,$isKuaigou,$qq,$huodong_miaoshu,$kgfanquan,$htfanquan,$kgservice,$htservice,$freight_ins,$zileimu)
	{
		
		$this->images      = $images;
		$this->shopid      = $shopid;
		$this->title      = $title;
		$this->content = $content;
		$this->distance      = $distance;
		$this->evaluate      = $evaluate;
		$this->reply      = $reply;
		$this->like      = $like;
		$this->phone      = $phone;
		$this->address      = $address;
		$this->logs      = $logs;
		$this->regs      = $regs;
		$this->category      = $category;
		$this->cityid      = $cityid;
		$this->city      = $city;
		$this->open      = $open;
		$this->start_price      = $start_price;
		$this->distribution_fee      = $distribution_fee;
		$this->song_da      = $song_da;
		$this->leimu      = $leimu;
		$this->alipay      = $alipay;
		$this->alipay_name      = $alipay_name;
		$this->weipay      = $weipay;
		$this->weipay_name      = $weipay_name;
		$this->licence      = $licence;
		$this->htservices      = $htservices;
		$this->kgservices      = $kgservices;
		$this->name      = $name;
		$this->isHaitao      = $isHaitao;
		$this->isKuaigou      = $isKuaigou;
		$this->qq      =  $qq;
		$this->huodong_miaoshu      =  $huodong_miaoshu;
		$this->kgfanquan      =  $kgfanquan;
		$this->htfanquan      =  $htfanquan;
		$this->kgservice      =  $kgservice;
		$this->htservice      =  $htservice;
		$this->freight_ins      =  $freight_ins;
		$this->zileimu      =  $zileimu;
	}
}



	//my_collect
	//获取收藏数
	$collectNum = 0;
	$collectCount = mysql_query('SELECT COUNT(*) FROM my_collect WHERE shopid = '.$_REQUEST['shopid'].' AND goodsid = 0');
	if($collectCount){
		$collectCountResult = mysql_fetch_array($collectCount);
		if($collectCountResult){
			$collectNum = $collectCountResult[0];
		}
	}
   $rert31=mysql_query("select * from shop where shopid='".$_REQUEST[shopid]."'");
   $prize = array();
   $rowf=mysql_fetch_array($rert31);

   $chaTime=date('Y-m-d',time()-3600*24*7);
   $rert23=mysql_query("select * from goods where shopid='".$_REQUEST[shopid]."'");
   $rert24=mysql_query("select * from goods where shopid='".$_REQUEST[shopid]."' where addtime>=".$chaTime." order by addtime desc");

   $numAll = mysql_num_rows($rert23);
   $numTian = mysql_num_rows($rert24);
	if(!$numTian){
		$numTian = 0;
	}
	$numInfo=array('numAll'=>$numAll,'numTian'=>$numTian,'collectNum'=>$collectNum );   
  
     $rert32=mysql_query("select * from user where userid='".$_REQUEST[userid]."'");
     $rowf3=mysql_fetch_array($rert32);

       $longitude1=$rowf3['longitude'];$latitude1=$rowf3['latitude'];$longitude2=$rowf['longitude'];$latitude2=$rowf['latitude'];
	   
	   function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) {
    $theta = $longitude1 - $longitude2;
    $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
    $miles = acos($miles);
    $miles = rad2deg($miles);
    $miles = $miles * 60 * 1.1515;
    $kilometers = $miles * 1.609344;
    return compact('kilometers'); 

}


$distance = getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2);
foreach ($distance as $unit => $value) {
    $dic= number_format($value,1);
}

$counts=mysql_query("select SUM(service) from goodsreply  where   shopid ='".$rowf['shopid']."'");

//评论数
$rss=mysql_fetch_array($counts);
$sum=$rss[0];



$count=mysql_query("select count(*) from goodsreply  where   shopid ='".$rowf['shopid']."'");

//评论数
$rs=mysql_fetch_array($count);
$totalNumber=$rs[0];
if ($totalNumber==0) {
	$ping=0;
}else{
	$ping=round(($sum/$totalNumber),2);
}
if($totalNumber==0 or $totalNumber=="")
{
$shu1=0;
}
else
{
$shu1=$totalNumber;
}

$count1=mysql_query("select count(*) from likes  where+ 
   shopid ='".$rowf['shopid']."'");

//点赞数
$rs1=mysql_fetch_array($count1);
$totalNumber1=$rs1[0];

if($totalNumber1==0 or $totalNumber1=="")
{
$shu=0;
}
else
{
$shu=$totalNumber1;
}
if($totalNumber!=0)
{
$sum=$totalNumber;
$ping=round(($sum/$totalNumber),2);
}
else
{
$ping=5;

}

if ($ping < 2) {
                            $pinfen = "<span></span><span class='empty'></span><span class='empty'></span><span class='empty'></span><span class='empty'></span>";
                        } 
						
						 else if ($ping < 3 and $ping > 2) {
                            $pinfen = "<span></span><span></span><span class='empty'></span><span class='empty'></span><span class='empty'></span>";
                        } 
						
						 else if ($ping < 4 and $ping > 3) {
                           $pinfen = "<span></span><span></span><span ></span><span class='empty'></span><span class='empty'></span>";
                        }
						 else if ($ping < 5 and $ping > 4) {
                           $pinfen = "<span></span><span></span><span ></span><span></span><span class='empty'></span>";
                        }
						 else  {
                           $pinfen = "<span></span><span></span><span ></span><span ></span><span ></span>";
                        }

$count2=mysql_query("select * from city  where   id ='".$rowf['city']."'");
$city=mysql_fetch_array($count2);
$addresss=$city['city'].$rowf['dian'].$rowf['address'];
// 证件照 
$licence = explode(',', $rowf[licence]);
if ($licence[0] == '') {
	$licence = array();
}
// 证件照 end

// 查找买家服务


$htservice = explode(',', $rowf[htservice]);
$htlen = count($htservice);
$htservices = array();
for ($i=0; $i < $htlen; $i++) { 
	$sql = mysql_query("select name from buyer_service where id=".$htservice[$i]);
	$service = mysql_fetch_assoc($sql);
	$htservices[] = $service[name];
}

$kgservice = explode(',', $rowf[kgservice]);
$htlen = count($kgservice);
$kgservices = array();
for ($i=0; $i < $htlen; $i++) { 
	$sql = mysql_query("select name from buyer_service where id=".$kgservice[$i]);
	$service = mysql_fetch_assoc($sql);
	$kgservices[] = $service[name];
}
// 查找买家服务 end
$resultArray = array();
$resultArray['code'] = 200;
$resultArray['msg'] = '获取成功';

//商品数量
$allAry = array();
$tiantianAry = array();

//查询子类目
$zileimuArray = array();
$zileimuQuery = mysql_query('select id as cateid,name from zifenlei where id in('.$rowf['zileimu'].')');
if($zileimuQuery){
	while ($zileimu_row = mysql_fetch_assoc($zileimuQuery)) {
		$zileimuArray[] = $zileimu_row;
	}
}
//$pinfen
$resultArray['data'] = new MyPrizeBean($rowf['images'],$rowf['shopid'],$rowf['name'],$rowf['content'],$dic,'',$totalNumber,$shu,$rowf['tel'],$addresss,$rowf['longitude'],$rowf['latitude'],$rowf['category'],$rowf['city'],$city['city'],$rowf['open'],$rowf['start_price'],$rowf['distribution_fee'],$rowf['song_da'],$rowf['leimu'],$rowf['alipay'],$rowf['alipay_name'],$rowf['weipay'],$rowf['weipay_name'],$licence,$htservices,$kgservices,$city['name'],$rowf['isHaitao'],$rowf['isKuaigou'],$rowf['qq'],$rowf['huodong_miaoshu'],$rowf['kgfanquan'],$rowf['htfanquan'],$rowf['kgservice'],$rowf['htservice'],$rowf['freight_ins'],$rowf['zileimu']);
$resultArray['num']= $numInfo;
$resultArray['zileimu_data'] = $zileimuArray;
echo json_encode($resultArray);


?>